#ifndef __DEF_VAR_H__
#define __DEF_VAR_H__

#pragma anon_unions
#ifdef __cplusplus
extern "C" {
#endif

#include "n32g030.h"

typedef  uint8_t  U8;                   	                   
typedef  uint16_t  U16;                   	                   
typedef  uint32_t  U32;                   	                   

#ifndef USE_TZ_SENSOR
#define	USE_TZ_SENSOR
#endif	

typedef     struct   LED_CTRL_TAG{
	union {
		U8    value;
		struct{
			U8   Power 	 :1;
			U8   Status  :1;
		}BIT;
	}STATUS;
	union {
		U8    value;
		struct{
			U8   Power 	 :1;
			U8   Status  :1;
		}BIT;
	}FLS;
	U16	LED_Flash_Time;
}LED_CTRL;

typedef    union   _ERROR_FLAG_TAG_{
	U16     value;
	struct{
		U8     	Ram_Err     : 1;
		U8			Program_Err	: 1;
		U8 	ChuChouYe_Err : 1;
		U8  Water_Err : 1;
		U8  AddWater_Err : 1;
		U8  AddChuChouYe_Err : 1;
	}BIT;
}ERROR_FLAG;

#define FLASH_PAGE_SIZE        ((uint16_t)0x100)
#define FLASH_WRITE_START_ADDR ((uint32_t)0x0800F000)
#define FLASH_WRITE_END_ADDR   ((uint32_t)0x08010000)
#define	SettingAddr	FLASH_WRITE_START_ADDR
#define	Setting_Item_Max 9
#define	Setting_Len (Setting_Item_Max)
#define	Time_Hour_Posi	7
#define	Time_Minute_posi	8
#define HXOffsetPosi 9
#define	HXCalibratePosi	10
#define	SETTING_IDLE_TIME	300
#define	LED_FLASH_TIME	5

#define	AddWaterWeight	1000
typedef struct 
{
	U16	min;
	U16 max;
	U16 step;
}
SETTING_ITEM;

typedef struct{
	union 
	{
		U32 data[Setting_Len];
		struct {
			U32 percent;				//1- 100,step 1
			U32 DayStartTime;	//hour,0 - 23 ,step 1
			U32 DayEndTime;		//hour,0 - 23 ,step 1
			U32 DayWorkTime;		//Second, 0 - 120 step 30
			U32 DayPauseTime;	//ssecond,30 - 900, step 30
			U32 NightWorkTime;	//Second, 0 - 120 step 30
			U32 NightPauseTime;//ssecond,30 - 900, step 30
			U32 Time_Hour;		//hour,0 - 23,step 1
			U32 Time_Minute;	//Second,0-60,step 1.
		}SetItem;
	};
	int32_t HXOffset;
	float HXCalibrate;
	U32	Count;	
	U32	ChkSum;
}SETTING_STRUCT;


typedef struct{
	U8 TZ_Status : 1;
	U8 UP_FUZI	: 1;
	U8	DW_FUZI	: 1;
}SENSOR;

enum {
	NO_KEY_PRESSED = 0,
	KEY1_PRESSED = 1,
	KEY2_PRESSED = 2,
	KEY3_PRESSED = 4,
	KEY4_PRESSED = 8,
	KEY_ZERO_PRESSED = 0x10,
	START_KEY = KEY1_PRESSED,
	CHOUYE_KEY = KEY2_PRESSED,
	LEDOFF_KEY = KEY3_PRESSED,
	SETTING_KEY = KEY4_PRESSED,
	FORWARD_KEY = START_KEY,
	MINUS_KEY = CHOUYE_KEY,
	PLUS_KEY = LEDOFF_KEY,
	BACKWARD_KEY = SETTING_KEY,
	KEY_MASK = 0x1f
};

#define	TZ_POWERON_TIME	100
typedef struct {
	U32	ChuChouYeWeight;
	U32 ChuChouYeNeed;
	U16	TZPowerOnTime;
	U8 TZSensorPower : 1;
	U8 TZSensorPowerOff:1;
	U8 ShuiFaPower : 1;
	U8 FanPower : 1;
	U8 ChuChouYePower : 1;
	U8 WuHuaPower : 1;
	U8 DeviceWorking : 1;
}MACHINESTATUS;

typedef struct {
	U16 WuHuaStatus;
	U16 WuHuaPowerOnTime;
	U16 WuHuaPowerOffTime;
	U32 WuHuaStatusChangeTime;
}
WUHUA_POWER_TIME;

enum {
	WUHUA_PowerOff = 0,
	WUHUA_PowerOn
};

enum {
	WATER_LOW_LEVEL = 0,
	WATER_NORMAL_LEVEL,
	WATER_HIGH_LEVEL,
	WATER_TOO_HIGH_LEVEL,
	WATER_ERROR = 0xff
};

enum{
	LEDON = 1,
	LEDOFF = 0,
	ALL_LEDON = 0x07,
	ALL_LEDOFF = 0x0,
	ALL_LED_FLASH_ON = 0x07,
	ALL_LED_FLASH_OFF = 0,
	LED_FLASH_ON = 1,
	LED_FLASH_OFF = 0,
	LED_POWER_ON_STS = 1,
	LED_START_WORKING = 2,
	LED_ALL = 3,
	LED_MASK = 3
};


enum { 
	NO = 0,
	YES
};


extern	SETTING_STRUCT CurSetting,BackupSetting;
//extern	U16 CurSettingValue[];
extern	LED_CTRL Led_Ctrl;
extern	SENSOR SensorNow,SensorLast;
extern	ERROR_FLAG Error_Flg;
extern	U16	swDelay;
extern	MACHINESTATUS machine;
extern	RTC_TimeType RTC_TimeStructure;
extern	WUHUA_POWER_TIME	WuHuaCtrl;
extern  U16 SettingPhase;


extern	const U32 initSetting [];
#ifdef __cplusplus
}
#endif

#endif /* __DEF_VAR_H__ */
